/*
 * Copyright (c) 2019 Nanjing Wind Information Co., Ltd. All Rights Reserved;
 * @Package wind.autotest.service
 * @version 1.0.0
 * @Date 2019年4月12日
 * @author jlliu.Farrior@wind.com.cn
 */
package wind.autotest.service.frontend;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import wind.autotest.dao.TestFieldDAO;
import wind.autotest.dao.TestTableDAO;
import wind.autotest.pojo.TestField;
import wind.autotest.pojo.TestTable;
import wind.autotest.util.Page4Navigator;

/**
 * @Description: <类功能描述>
 * @author jlliu.Farrior@wind.com.cn
 * @Date 2019年4月12日 下午1:34:19
 * 
 */
@Service
public class TestFieldService {	
	@Autowired
	private TestTableDAO tableDAO;
	@Autowired
	private TestFieldDAO fieldDAO;
	
	public Page4Navigator<TestField> list(int table_id, int start, int size, int navigatePages) {
		// TODO null处理
		TestTable testTable = tableDAO.findOne(table_id);		
		Sort sort = new Sort(Sort.Direction.DESC, "id");
		Pageable pageable = new PageRequest(start, size,sort);
		Page<TestField> pageFromJPA = fieldDAO.findByTestTable(testTable, pageable);
		return new Page4Navigator<>(pageFromJPA,navigatePages);
	}

	public void add(TestField bean) {
		fieldDAO.save(bean);
	}

	public void delete(int id) {
		fieldDAO.delete(id);
	}

	public TestField get(int id) {
		TestField fieldbean= fieldDAO.findOne(id);
		return fieldbean;
	}
	
	public void update(TestField bean) {
		fieldDAO.save(bean);
	}
	
	public List<TestField> findBussKeyFields(int table_id) {
		// TODO null处理
		return fieldDAO.findBussKeyFields(table_id);
	}
	
}
